﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Forms;

namespace HYCodeBase.WinForm.WinFormRemindSuit
{
	internal class SpecialControlAttributeGeter : IAttributeGeter
	{
		private SpecialControlAttributeGeter()
		{
		}

		internal static SpecialControlAttributeGeter GetSpecialControlPropertyGeter()
		{
			if (SpecialControlAttributeGeter.m_singleTag == null)
			{
				SpecialControlAttributeGeter.m_singleTag = new SpecialControlAttributeGeter();
			}
			return SpecialControlAttributeGeter.m_singleTag;
		}

		public AttributeInformationBean GetOneAttributeBean(Control inputControl, string inputAttributeName)
		{
			AttributeInformationBean result = null;
			try
			{
				string controlAttribute = this.GetControlAttribute(inputControl);
				result = new AttributeInformationBean(inputAttributeName, controlAttribute);
			}
			catch (Exception)
			{
			}
			return result;
		}

		private string GetControlAttribute(Control inputControl)
		{
			List<string> list = new List<string>();
			string text = string.Empty;
			if (inputControl is TreeView)
			{
                IEnumerator enumerator = (inputControl as TreeView).Nodes.GetEnumerator();
				{
					while (enumerator.MoveNext())
					{
						object obj = enumerator.Current;
						TreeNode treeNode = (TreeNode)obj;
						if (treeNode.Checked)
						{
							text = text + SpecialControlAttributeGeter.m_strParentNodeCheckedTag + "-";
						}
						else
						{
							text += SpecialControlAttributeGeter.m_strParentNodeUnCheckedTag;
                            IEnumerator enumerator2 = treeNode.Nodes.GetEnumerator();
							{
								while (enumerator2.MoveNext())
								{
									if (((TreeNode)enumerator2.Current).Checked)
									{
										text = text + "," + SpecialControlAttributeGeter.m_strChildNodeCheckedTag;
									}
									else
									{
										text = text + "," + SpecialControlAttributeGeter.m_strChildNodeUnCheckedTag;
									}
								}
							}
							text += "-";
						}
					}
					return text;
				}
			}
			if (inputControl is ListView)
			{
                IEnumerator enumerator = (inputControl as ListView).Items.GetEnumerator();
				{
					while (enumerator.MoveNext())
					{
						if (((ListViewItem)enumerator.Current).Checked)
						{
							text = text + SpecialControlAttributeGeter.m_strParentNodeCheckedTag + ",";
						}
						else
						{
							text = text + SpecialControlAttributeGeter.m_strParentNodeUnCheckedTag + ",";
						}
					}
					return text;
				}
			}
			if (inputControl is CheckedListBox)
			{
				for (int i = 0; i < (inputControl as CheckedListBox).Items.Count; i++)
				{
					if ((inputControl as CheckedListBox).GetItemChecked(i))
					{
						text = text + SpecialControlAttributeGeter.m_strParentNodeCheckedTag + ",";
					}
					else
					{
						text = text + SpecialControlAttributeGeter.m_strParentNodeUnCheckedTag + ",";
					}
				}
			}
			else if (inputControl is ListBox)
			{
				foreach (object obj2 in (inputControl as ListBox).Items)
				{
					list.Add(obj2.ToString());
				}
				text = this.BuildString(list);
			}
			return text;
		}

		private string BuildString(List<string> lststr)
		{
			string text = null;
			foreach (string str in lststr)
			{
				text = text + str + ",";
			}
			return text;
		}

		private static SpecialControlAttributeGeter m_singleTag = null;

		private static string m_strParentNodeCheckedTag = "ParentNodeChecked";

		private static string m_strParentNodeUnCheckedTag = "ParentNodeUnChecked";

		private static string m_strChildNodeCheckedTag = "ChildNodeChecked";

		private static string m_strChildNodeUnCheckedTag = "ChildNodeUnChecked";
	}
}
